package com.yojcodesendbox.codesendbox.impl;

import com.yojcodesendbox.codesendbox.CodeSandbox;
import com.yojcodesendbox.codesendbox.ExecuteBase;
import com.yojcodesendbox.codesendbox.ExecuteCodeTemplate;
import com.yojcodesendbox.constant.FileConstant;
import com.yojcodesendbox.model.ExecuteCodeRequest;
import com.yojcodesendbox.model.ExecuteCodeResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class CPlusPlusNativeCodeSendbox extends CodeSandbox implements ExecuteBase {
    @Resource
    ExecuteCodeTemplate executeCodeTemplate;
    @Resource
    private FileConstant fileConstant;

    public ExecuteCodeResponse executeCode(ExecuteCodeRequest executeCodeRequest) {
        return execute("g++ -o %s\\Main %s\\Main.cpp", "%s\\Main", executeCodeRequest);
    }

    @Override
    public ExecuteCodeResponse execute(String compileCmd, String executeCmd, ExecuteCodeRequest executeCodeRequest) {
        executeCodeTemplate.setCompilCmd(compileCmd);
        executeCodeTemplate.setExecmdStringFormat(executeCmd);
        executeCodeTemplate.setFileTail(fileConstant.cPlusPLusTailFix);
        return executeCodeTemplate.executeCode(executeCodeRequest);
    }
}
